package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.PartnerFinanceRelationVO;
import com.yunxi.sto.service.PartnerFinanceRelationDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 渠道商融资机构关系 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-09-17
 */
@RestController
@RequestMapping("/admin/partnerFinanceRelation")
@Api(tags = "sto:partnerFinanceRelation", description = "渠道商融资机构关系接口")
public class PartnerFinanceRelationController {
    private static final Logger logger = LoggerFactory.getLogger(PartnerFinanceRelationController.class);

    @Autowired
    PartnerFinanceRelationDubboService partnerFinanceRelationDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询渠道商融资机构关系分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult page(PartnerFinanceRelationVO partnerFinanceRelationVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(partnerFinanceRelationDubboService.findPageByVO(partnerFinanceRelationVO, pageNum, pageSize));
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出")
    public ApiResult export(PartnerFinanceRelationVO partnerFinanceRelationVO) throws Exception {
        return ResponseUtil.ok(partnerFinanceRelationDubboService.export(partnerFinanceRelationVO));
    }

    @PostMapping("/import")
    @ApiOperation(value = "导入")
    public ApiResult importSave(@RequestBody List<PartnerFinanceRelationVO> list, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerFinanceRelationDubboService.importSave(list);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询渠道商融资机构关系列表")
    public ApiResult list(PartnerFinanceRelationVO partnerFinanceRelationVO) throws Exception {
        return ResponseUtil.ok(partnerFinanceRelationDubboService.listByVo(partnerFinanceRelationVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个渠道商融资机构关系")
    @ApiImplicitParam(paramType="query", name = "relationId", value = "主键ID", required = true, dataType = "String")
    public ApiResult load(String relationId) throws Exception {
        return ResponseUtil.ok(partnerFinanceRelationDubboService.getById(relationId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存渠道商融资机构关系信息")
    public ApiResult save(@RequestBody PartnerFinanceRelationVO partnerFinanceRelationVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        partnerFinanceRelationDubboService.saveOrUpdate(partnerFinanceRelationVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "停用")
    public ApiResult del(@RequestBody List<String> list) throws Exception {
        partnerFinanceRelationDubboService.delAndReset(list,0);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/reset")
    @ApiOperation(value = "启用")
    public ApiResult reset(@RequestBody List<String> list) throws Exception {
        partnerFinanceRelationDubboService.delAndReset(list,1);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/listByPartnerCode")
    @ApiOperation(value = "根据渠道代码查询融资机构信息")
    @ApiImplicitParam(paramType="query", name = "partnerCode", value = "渠道代码", required = true, dataType = "String")
    public ApiResult listByPartnerCode(String partnerCode) throws Exception {
        return ResponseUtil.ok(partnerFinanceRelationDubboService.listByPartnerCode(partnerCode));
    }

    @GetMapping("/listByVin")
    @ApiOperation(value = "根据VIN查询融资机构信息")
    @ApiImplicitParam(paramType="query", name = "vin", value = "VIN码", required = true, dataType = "String")
    public ApiResult listByVin(String vin) throws Exception {
        return ResponseUtil.ok(partnerFinanceRelationDubboService.listByVin(vin));
    }

    @GetMapping("/accountType")
    @ApiOperation(value = "获取有效付款方式")
    public ApiResult accountType() throws Exception {
        return ResponseUtil.ok(partnerFinanceRelationDubboService.accountType());
    }
}
